package com.smart.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.manage.domain.HealthArticle;
import com.smart.manage.service.IHealthArticleService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 健康百科文章Controller
 * 
 * @author lingyao
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/manage/healthArticle")
public class HealthArticleController extends BaseController
{
    @Autowired
    private IHealthArticleService healthArticleService;

    /**
     * 查询健康百科文章列表
     */
    @PreAuthorize("@ss.hasPermi('manage:healthArticle:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthArticle healthArticle)
    {
        startPage();
        List<HealthArticle> list = healthArticleService.selectHealthArticleList(healthArticle);
        return getDataTable(list);
    }

    /**
     * 导出健康百科文章列表
     */
    @PreAuthorize("@ss.hasPermi('manage:healthArticle:export')")
    @Log(title = "健康百科文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthArticle healthArticle)
    {
        List<HealthArticle> list = healthArticleService.selectHealthArticleList(healthArticle);
        ExcelUtil<HealthArticle> util = new ExcelUtil<HealthArticle>(HealthArticle.class);
        util.exportExcel(response, list, "健康百科文章数据");
    }

    /**
     * 获取健康百科文章详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:healthArticle:query')")
    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable("articleId") Long articleId)
    {
        return success(healthArticleService.selectHealthArticleByArticleId(articleId));
    }

    /**
     * 新增健康百科文章
     */
    @PreAuthorize("@ss.hasPermi('manage:healthArticle:add')")
    @Log(title = "健康百科文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthArticle healthArticle)
    {
        return toAjax(healthArticleService.insertHealthArticle(healthArticle));
    }

    /**
     * 修改健康百科文章
     */
    @PreAuthorize("@ss.hasPermi('manage:healthArticle:edit')")
    @Log(title = "健康百科文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthArticle healthArticle)
    {
        return toAjax(healthArticleService.updateHealthArticle(healthArticle));
    }

    /**
     * 删除健康百科文章
     */
    @PreAuthorize("@ss.hasPermi('manage:healthArticle:remove')")
    @Log(title = "健康百科文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable Long[] articleIds)
    {
        return toAjax(healthArticleService.deleteHealthArticleByArticleIds(articleIds));
    }
}
